/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilidades;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Dados unos parametros crea y devuelve una URL.
 *
 * @author felipe
 */
public class ConstructorURL {

    private int fromMonth;
    private int fromDay;
    private int fromYear;
    private int toMonth;
    private int toDay;
    private int toYear;
    private String interval;

    public ConstructorURL(int fromMonth, int fromDay, int fromYear, int toMonth, int toDay, int toYear, String interval) {
        this.fromMonth = fromMonth - 1;
        this.fromDay = fromDay;
        this.fromYear = fromYear;
        this.toMonth = toMonth - 1;
        this.toDay = toDay;
        this.toYear = toYear;
        this.interval = interval;
    }

    /**
     * Dado un id que representa un valor de la bolsa y otros datos, construye
     * la URL para descargar la info.
     *
     * @param id
     * @return URL
     */
    public URL urlCreator(String id) {
        URL url = null;
        try {
            url = new URL("http://ichart.yahoo.com/table.csv?s=" + id
                    + "&a=" + fromMonth + "&b=" + fromDay + "&c=" + fromYear
                    + "&d=" + toMonth + "&e=" + toDay + "&f=" + toYear
                    + "&g=" + interval + "&ignore=.csv");
        } catch (MalformedURLException ex) {
            Logger.getLogger(ConstructorURL.class.getName()).log(Level.SEVERE, null, ex);
        }
        return url;
    }
}